package study.web.service.jaxws.client;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import study.web.service.jaxws.impl.Weather;
import study.web.service.jaxws.impl.WeatherInterface;
import study.web.service.jaxws.pojo.WeatherModel;

/**  
* @Name: WeatherClient
* @Description: 天气信息查询客户端
* @Author: 李超
* @version 1.0
* @Create Date: 2017-01-06
*/
public class WeatherClient {
	
	public static void main(String[] args) throws MalformedURLException {
		//1、创建webservice服务发布的url
		URL url = new URL("http://127.0.0.1:8080/jaxws_web_soap11_server/ws/weather?wsdl") ;
		//2、创建webservice服务的限定名称
		QName qName = new QName("http://impl.jaxws.service.web.study", "WeatherService") ;
		//3、创建服务视图对象
		Service service = Service.create(url, qName);
		//4、获取portType对象
		WeatherInterface weatherInterface = service.getPort(WeatherInterface.class) ;
		//5、调用服务方法，获取响应数据
		List<Weather> weatherList = weatherInterface.queryWeatherByCityName("北京") ;
		//6、将响应数据转换为客户端对象集合
		List<WeatherModel> list = null ;
		if(weatherList != null && weatherList.size() > 0) {
			list = new ArrayList<>() ;
			for (Weather weather : weatherList) {
				WeatherModel weatherModel = new WeatherModel() ;
				weatherModel.setDetail(weather.getDetail()) ;
				weatherModel.setDate(weather.getDate().toGregorianCalendar().getTime()) ;
				weatherModel.setTemperature_max(weather.getTemperatureMax()) ;
				weatherModel.setTemperature_min(weather.getTemperatureMin()) ;
				list.add(weatherModel) ;
			}
		}
		for (WeatherModel weatherModel : list) {
			System.out.println(weatherModel);
		}
	}

}
